<template>
	<view class="login">
		<cu-custom :bgColor="bgColor"></cu-custom>
		<view class="login-content">
			<view class="tabs-box">
				<view class="tabs__item" :class="activeTabs == 0 ? 'active' : ''" @click="changeTabs(0)">手机登录</view>
				<view class="tabs__item" :class="activeTabs == 1 ? 'active' : ''" @click="changeTabs(1)">扫码登录</view>
				<view class="tabs__item" :class="activeTabs == 2 ? 'active' : ''" @click="changeTabs(2)">邮箱登录</view>
			</view>
			<!-- 手机登录 -->
			<view class="phone-login" v-if="activeTabs == 0">
				<view class="form-line phone-box">
					<image class="icon icon-phone" src="/static/images/login/icon-phone.png" mode="widthFix"></image>
					<text>手机号</text>
					<u--input placeholder="请输入手机号码" maxlength="11" border="none" clearable></u--input>
				</view>
				<view class="form-line code-box">
					<image class="icon icon-code" src="/static/images/login/icon-code.png" mode="widthFix"></image>
					<text>验证码</text>
					<u-input placeholder="请输入验证码" border="none" clearable>
						<template slot="suffix">
							<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
							<view @tap="getCode">{{tips}}</view>
						</template>
					</u-input>
				</view>
				<button class="login-btn" @click="login">登录</button>
			</view>
			<!-- 扫码登录 -->
			<view class="qrcode-box" v-if="activeTabs == 1">
				<tki-qrcode class="text-center p-t20 p-b20" cid="qrcode2" ref="qrcode2" :val="val" :size="370" :onval="onval" :loadMake="loadMake" :usingComponents="true" :showLoading="false" @result="qrR" />
				<view class="qrcode-tips">使用小红书扫码登录</view>
			</view>
			<!-- 邮箱登录 -->
			<view class="phone-login" v-if="activeTabs == 2">
				<view class="form-line phone-box">
					<image class="icon icon-phone" src="/static/images/login/icon-email.png" mode="widthFix"></image>
					<text>邮箱</text>
					<u-input placeholder="请输入邮箱账号" maxlength="11" border="none" clearable></u-input>
				</view>
				<view class="form-line code-box">
					<image class="icon icon-code" src="/static/images/login/icon-code.png" mode="widthFix"></image>
					<text>密码</text>
					<u-input placeholder="请输入密码" border="none" clearable></u-input>
				</view>
				<button class="login-btn" @click="login">登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgColor:'transparent',
				// 登陆选项切换
				activeTabs: 0,
				tips: '',
				// 二维码信息
				val:'3123123123',
				onval:true,//监听val值变化自动重新生成二维码
				loadMake:true,//组件初始化完成后自动生成二维码，val需要有值
			};
		},
		methods: {
			// 登录切换
			changeTabs(status) {
				this.activeTabs = status
			},
			qrR(res) {
				this.qrSrc = res
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			// 登录
			login() {
				console.log('登录成功')
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}
	.login {
		height: 100%;
		overflow: hidden;
		background: url('/static/images/login/logo.png') no-repeat top center;
		background-size: 100% 600rpx;
		background-color: #F0F1F5;
	}
	.login-content {
		margin: 300rpx 75rpx 0;
	}
	.phone-login {
		margin-top: 73rpx;
	}
	.tabs-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.tabs__item {
		position: relative;
	}
	.active {
		&::after {
			width: 64rpx;
			height: 14rpx;
			content: '';
			background: #3662EC;
			border-radius: 4rpx;
			position: absolute;
			bottom: -7rpx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
	.form-line {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx;
		background: #fff;
		border-radius: 16rpx;
		text {
			margin-left: 10rpx;
			margin-right: 20rpx;
		}
	}
	.code-box {
		margin-top: 30rpx;
	}
	.icon {
		width: 36rpx;
		height: 36rpx;
		display: block;
	}
	::v-deep .u-input__content__subfix-icon {
		font-size: 26rpx;
		color: #3662EC;
	}
	.login-btn {
		margin-top: 60rpx;
		height: 96rpx;
		border-radius: 16rpx;
		background: #3662EC;
		line-height: 96rpx;
		color: #fff;
		font-size: 30rpx;
		font-weight: bold;
	}
	.qrcode-box {
		margin-top: 73rpx;
		padding: 126rpx 115rpx 188rpx;
		background: #fff;
		border-radius: 16rpx;
	}
	.qrcode-tips {
		font-size: 26rpx;
		color: #666;
		margin-top: 20rpx;
		text-align: center;
	}
</style>